package com.shuyun.xxx.guava.offer;

/**
 * Created by goodb on 2017/5/21.
 * 打印两个有序链表的公共部分
 */
public class PrintCommonLinked {
    private static class Node{
        public int data;
        public Node next;
        public Node(int data){
            this.data = data;
        }
    }

    public void printCommon(Node node1, Node node2){
        System.out.println("链表的公共部分为:");
        while(node1 != null && node2 != null){
            if(node1.data < node2.data){
                node1 = node1.next;
            }else if(node1.data > node2.data){
                node2 = node2.next;
            }else{
                System.out.println("common value: ");
                node1 = node1.next;
                node2 = node2.next;
            }
        }
    }
}
